﻿using Keyence.AutoID.SDK;
using NDK.Module.Model;

namespace NDK.Utils
{
    public class KeyenceScanReader
    {
        private ReaderAccessor m_reader = null;
        private string _readerIP = "192.169.100.100";
        public string ReaderIP
        {
            get { return _readerIP; }
            set { _readerIP = value; }
        }

        public bool ConnectReader()
        {
            m_reader = new ReaderAccessor(_readerIP);
            return m_reader.Connect();
        }

        public void DisconnectReader()
        {
            m_reader.Disconnect();
        }

        public string TrigReader(int timeoutms, string command = "LON" + "\r\n")
        {
            string mes = m_reader.ExecCommand(command, timeoutms);
            if (Common.Line == "MUR")
            {
                m_reader.ExecCommand($"LOFF\r\n");
            }
            return mes;
        }

        public void Dispose()
        {
            m_reader.Dispose();
        }
    }
}
